package com.shwread.android.qysw.step.api;

import android.content.Context;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.util.Log;

import com.shwread.android.qysw.tools.BitmapUtil;

import java.io.IOException;

/**
 * Created by fantasy on 16/4/27.
 */
public class GetPhotoAsynctask extends AsyncTask<String, Void, Bitmap> {
    public Context mContext;
    public RequestListener mRequestListener;

    public GetPhotoAsynctask(Context context, RequestListener requestListener) {
        this.mContext = context;
        this.mRequestListener = requestListener;
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    protected Bitmap doInBackground(String... params) {
      String url =params[0];
        Bitmap bitmap=null;
        try {
            bitmap= BitmapUtil.getBitmap(url);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return bitmap;
    }

    @Override
    protected void onPostExecute(Bitmap bitmap) {
        Log.i("darren","bitmap:"+bitmap+"");
        super.onPostExecute(bitmap);
        mRequestListener.requestSuccess(bitmap);
    }

    public interface RequestListener {
        void requestSuccess(Bitmap result);
    }



}

